﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using FixEd.Parsers;

namespace FixEd
{
    public partial class FileForm : Form
    {
        private int _CurrentFrozenColumn;
        /// <summary>
        /// Represents the current state of the data inside the datagridview
        /// </summary>
        private DataSet _CurrentDataSet;
        /// <summary>
        /// Represents the DataSet as it was originally parsed
        /// </summary>
        private DataSet _OriginalDataSet;

        public FileForm()
        {
            InitializeComponent();
        }

        /// <remarks>Make sure this merges with parent</remarks>
        private void TsReportingVisible_Click(object sender, EventArgs e)
        {

        }

        private void FileForm_Load(object sender, EventArgs e)
        {

        }



        /// <summary>
        /// Clicking on grid will select the whole column
        /// </summary>
        private void TsSelectionColumn_Click(object sender, EventArgs e)
        {
            BreakSorting(true);
            DgvDocument.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;
        }

        /// <summary>
        /// Selection is by individual cell (default)
        /// </summary>
        private void TsSelectionCell_Click(object sender, EventArgs e)
        {
            
            DgvDocument.SelectionMode = DataGridViewSelectionMode.CellSelect;
            BreakSorting(false);
        }

        /// <summary>
        /// Clicking on grid will select the whole row
        /// </summary>
        private void TsSelectionRow_Click(object sender, EventArgs e)
        {
            BreakSorting(true);
            DgvDocument.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }

        private void BreakSorting(bool shouldBreak)
        {
            if (shouldBreak)
            {
                for (int i = 0; i < DgvDocument.Columns.Count; i++)
                {
                    DgvDocument.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic;
                }
                return;
            }
            for (int i = 0; i < DgvDocument.Columns.Count; i++)
            {
                DgvDocument.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
            }

        }



        /// <summary>
        /// Freezes the current column
        /// </summary>
        private void FreezeColumn(DataGridViewCellStyle style)
        {
            DgvDocument.SelectedColumns[0].Frozen = true;
            _CurrentFrozenColumn = DgvDocument.SelectedColumns[0].Index;

            style.BackColor = Color.WhiteSmoke;
            DgvDocument.SelectedColumns[0].DefaultCellStyle = style;
        }

        /// <summary>
        /// Unlocks any frozen columns
        /// </summary>
        private void UnfreezeColumn(DataGridViewCellStyle style)
        {
            DgvDocument.Columns[_CurrentFrozenColumn].Frozen = false;
            style.BackColor = Color.White;
            DgvDocument.Columns[_CurrentFrozenColumn].DefaultCellStyle = style;
            DgvDocument.Columns[0].Frozen = false;

            return;
        }


    }
}
